#! /usr/bin/env python2
# Derived from camera1394 cfg

from dynamic_reconfigure.parameter_generator_catkin import *

RECONFIGURE_CLOSE = 3 # Parameters that need a sensor to be stopped completely when changed
RECONFIGURE_STOP = 1 # Parameters that need a sensor to stop streaming when changed
RECONFIGURE_RUNNING = 0 # Parameters that can be changed while a sensor is streaming

gen = ParameterGenerator()

#       Name, Type, Reconfiguration level, Description, Default, Min, Max

gen.add("vendor", str_t, RECONFIGURE_CLOSE,
        "Vendor ID, hex digits (use camera of any vendor if null).",
        "")

gen.add("product", str_t, RECONFIGURE_CLOSE,
        "Product ID, hex digits (use camera of any model if null).",
        "")

gen.add("serial", str_t, RECONFIGURE_CLOSE,
        "Serial number, arbitrary string (use camera of any serial number if null).",
        "")

gen.add("index", int_t, RECONFIGURE_CLOSE,
        "Index into the list of cameras that match the above parameters.",
        0, 0)

gen.add("width", int_t, RECONFIGURE_CLOSE,
        "Image width.", 640, 0)

gen.add("height", int_t, RECONFIGURE_CLOSE,
        "Image height.", 480, 0)

video_modes = gen.enum([gen.const("uncompressed", str_t, "uncompressed", "Use any uncompressed format"),
                        gen.const("compressed", str_t, "compressed", "User any compressed format"),
                        gen.const("yuyv", str_t, "yuyv", "YUYV"),
                        gen.const("uyvy", str_t, "uyvy", "UYVY"),
                        gen.const("rgb", str_t, "rgb", "RGB"),
                        gen.const("bgr", str_t, "bgr", "BGR"),
                        gen.const("mjpeg", str_t, "mjpeg", "MJPEG"),
                        gen.const("gray8", str_t, "gray8", "gray8")],
                       "Video stream format")

gen.add("video_mode", str_t, RECONFIGURE_CLOSE,
        "Format of video stream from camera.", "uncompressed",
        edit_method = video_modes)

gen.add("frame_rate", double_t, RECONFIGURE_CLOSE,
        "Camera speed, frames per second.", 15.0, 0.1, 1000.0)

timestamp_methods = gen.enum([gen.const("PubTime", str_t, "pub", "Time of publication"),
                              gen.const("FrameStartTime", str_t, "start", "Time when raw frame capture began"),
                              gen.const("FrameStopTime", str_t, "stop", "Time when raw frame capture ended"),
                              gen.const("HostReceiptTime", str_t, "hostrcpt", "Time when camera-to-host transfer completed")],
                             "Methods for determining the timestamp")

gen.add("timestamp_method", str_t, RECONFIGURE_CLOSE,
        "Method for determining the timestamp.", "start",
        edit_method = timestamp_methods)

gen.add("frame_id", str_t, RECONFIGURE_RUNNING,
        "ROS tf frame of reference, resolved with tf_prefix unless absolute.",
        "camera")

gen.add("camera_info_url", str_t, RECONFIGURE_RUNNING,
        "Path to camera calibration file.", "")

# Camera Terminal controls

scanning_modes = gen.enum([gen.const("Interlaced", int_t, 0, ""),
                           gen.const("Progressive", int_t, 1, "")],
                          "Scanning modes")

gen.add("scanning_mode", int_t, RECONFIGURE_RUNNING,
        "Scanning mode.", 0, 0, 1,
        edit_method = scanning_modes)

auto_exposure_modes = gen.enum([gen.const("Manual", int_t, 0, "Manual exposure, manual iris"),
                                gen.const("Auto", int_t, 1, "Auto exposure, auto iris"),
                                gen.const("Shutter_Priority", int_t, 2, "manual exposure, auto iris"),
                                gen.const("Aperture_Priority", int_t, 3, "auto exposure, manual iris")],
                               "Auto-exposure modes")

gen.add("auto_exposure", int_t, RECONFIGURE_RUNNING,
        "Auto exposure mode.",
        3, 0, 3, edit_method = auto_exposure_modes)

gen.add("auto_exposure_priority", int_t, RECONFIGURE_RUNNING,
        "In auto mode or shutter priority mode, allow the device to vary frame rate.",
        0, 0, 1)

gen.add("exposure_absolute", double_t, RECONFIGURE_RUNNING,
        "Length of exposure, seconds.", 0., 0.0001, 10.0)

# TODO: relative exposure time

gen.add("iris_absolute", double_t, RECONFIGURE_RUNNING,
        "Aperture, f.", 0., 0., 655.35)

# TODO: relative iris

gen.add("auto_focus", bool_t, RECONFIGURE_RUNNING,
        "Maintain focus automatically.", True)

gen.add("focus_absolute", int_t, RECONFIGURE_RUNNING,
        "Absolute focal distance, millimeters.", 0, 0, 65536)

# TODO: relative focus

# TODO: zoom

gen.add("pan_absolute", int_t, RECONFIGURE_RUNNING,
        "Pan (clockwise), arc seconds.", 0, -180*3600, 180*3600)

gen.add("tilt_absolute", int_t, RECONFIGURE_RUNNING,
        "Tilt (up), arc seconds.", 0, -180*3600, 180*3600)

# TODO: relative pan/tilt

gen.add("roll_absolute", int_t, RECONFIGURE_RUNNING,
        "Roll (clockwise), degrees.", 0, -180, 180)

# TODO: relative roll

gen.add("privacy", bool_t, RECONFIGURE_RUNNING,
        "Image capture disabled.", False)

# Processing Unit controls

gen.add("backlight_compensation", int_t, RECONFIGURE_RUNNING,
        "Backlight compensation, device-dependent (zero for none, increasing compensation above zero).",
        0, 0, 65536)


gen.add("brightness", int_t, RECONFIGURE_RUNNING,
        "Brightness, device dependent.", 0, -32768, 32767)

gen.add("contrast", int_t, RECONFIGURE_RUNNING,
        "Contrast, device dependent.", 0, -32768, 32767)

gen.add("gain", int_t, RECONFIGURE_RUNNING,
        "Gain, device dependent.", 0, 0, 65536)

power_line_frequency_modes = gen.enum([gen.const("Disabled", int_t, 0, "Disabled"),
                                       gen.const("Freq_50", int_t, 1, "50 Hz"),
                                       gen.const("Freq_60", int_t, 1, "60 Hz")],
                                      "Power line frequency modes")

gen.add("power_line_frequency", int_t, RECONFIGURE_RUNNING,
        "Power line frequency anti-flicker processing.",
        0, 0, 2,
        edit_method = power_line_frequency_modes)

gen.add("auto_hue", bool_t, RECONFIGURE_RUNNING,
        "Automatic hue control.", False)

gen.add("hue", double_t, RECONFIGURE_RUNNING,
        "Hue, degrees.", 0., -180., 180.)

gen.add("saturation", int_t, RECONFIGURE_RUNNING,
        "Saturation, device dependent (zero for grayscale).", 0, 0, 65536)

gen.add("sharpness", int_t, RECONFIGURE_RUNNING,
        "Image sharpness, device dependent.",
        0, 0, 65536)

# TODO: check range definition
gen.add("gamma", double_t, RECONFIGURE_RUNNING,
        "Gamma.", 1.0, 0.01, 5.0)

gen.add("auto_white_balance", bool_t, RECONFIGURE_RUNNING,
        "Automatic white balance.", False)

gen.add("white_balance_temperature", int_t, RECONFIGURE_RUNNING,
        "White balance temperature, degrees.", 0, 0, 65536)

gen.add("white_balance_BU", double_t, RECONFIGURE_RUNNING,
        "Blue or U component of white balance, device-dependent.",
        0, 0, 65536)

gen.add("white_balance_RV", double_t, RECONFIGURE_RUNNING,
        "Red or V component of white balance, device-dependent.",
        0, 0, 65536)

# TODO: digital multiplier {,limit}

# TODO: analog video standard, analog video lock

exit(gen.generate('libuvc_camera', "libuvc_camera", "UVCCamera"))
